#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <arpa/inet.h>




int main(int argc, char *argv[])
{
	int i;
	if(argc < 2){
		printf("%s <host name>\n", argv[0]);
		exit(0);
	}
	//根据传入的域名，获取对应的结构体
	struct hostent *host = gethostbyname(argv[1]);

	//别名
	for(i = 0; host->h_aliases[i] != NULL; i++){
		printf("%s\n", host->h_aliases[i]);
	}
	//IP类型
	printf("Address type:%s\n",
			host->h_addrtype == AF_INET ? "AF_INET":"AF_INET6");

	//IP列表
	for(i = 0; host->h_addr_list[i] != NULL; i++){
		//inet_ntoa入参要求是 struct in_addr
		printf("IP address %d:%s\n", i, inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
	}
	endhostent();
	return 0;
}
